/**
 * HR 月评
 */
import React from 'react';
import { Collapse } from '@/molecules';
import { useCollapse } from '@/hooks';
import { Form } from 'antd';
import {
    AssessAbilityResult,
    Attendance,
    AssessHRDetail,
    DetailDiscussArrange,
    AssessResultDynamic,
    AssessKPI
} from '../containers';
import { useAssessSetting } from '../hooks';
import { TRIAL_ACTION } from '../constants';

const { Panel } = Collapse;

function AssessHRM({ data = {} }) {
    const { assessMonthly = [] } = data;
    const { activeKey, onChange } = useCollapse(['1', '2', '3', '4', '5', '6'], []);
    const { m } = useAssessSetting(data);

    const hrDetail = React.useMemo(() => assessMonthly.find(item => item.status === TRIAL_ACTION.ASSESS_HR_MONTH), []);
    const assessDetail = React.useMemo(
        () => assessMonthly.filter(item => item.status !== TRIAL_ACTION.ASSESS_HR_MONTH),
        []
    );

    // 人事评价 evaluationType 0:不合格 1:合格 2:需观察
    const showDiscuss = React.useMemo(() => ['0', '2'].includes(hrDetail?.evaluationType), [hrDetail]);

    return (
        <div>
            <Collapse bordered={false} activeKey={activeKey} onChange={onChange}>
                <AssessResultDynamic data={data} />
                {m.showKPI && Boolean(data?.performanceTarget?.result) && (
                    <Panel header="季度绩效目标" key="2">
                        <AssessKPI data={data} />
                    </Panel>
                )}
                {m.showAssess && (
                    <Panel header="能力评估" key="3">
                        <AssessAbilityResult
                            data={assessDetail}
                            levels={data?.assessAbility?.levels}
                            employeeCode={data?.employeeCode}
                        />
                    </Panel>
                )}
                <Panel header="考勤情况" key="4">
                    <Attendance data={data} type="month" />
                </Panel>
                <Panel header="人事评估意见" key="5">
                    <AssessHRDetail data={hrDetail} />
                </Panel>
                {showDiscuss && (
                    <Panel header="新员工面谈安排" key="6">
                        <DetailDiscussArrange data={hrDetail?.interviewArrange} />
                    </Panel>
                )}
            </Collapse>
        </div>
    );
}

export default Form.create({})(AssessHRM);
